package com.example.webbackend.controller;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/model")
public class DeepSeekChatModelController {

    private final ChatModel deepSeekChatModel;

    @Autowired
    public DeepSeekChatModelController(ChatModel chatModel) {
        this.deepSeekChatModel = chatModel;
    }

    /**
     * 接收用户输入的 prompt 参数
     * @param prompt 用户输入的提问内容
     * @return 返回模型的回答
     */
    @GetMapping("/simple/chat")
    public String simpleChat(@RequestParam(name = "prompt", required = false, defaultValue = "你好，介绍下你自己吧。") String prompt) {
        return deepSeekChatModel.call(new Prompt(prompt))
                .getResult()
                .getOutput()
                .getText();
    }
}
